# msg queue
import queue
import numpy as np


class imageQueue:
    imageQueueMap = {}
    lastImgMap = {}
    queuePoolSize = 10

    @classmethod
    def putImgToQueue(cls, roomId: str, img:np):
        if cls.imageQueueMap.keys().__contains__(roomId):
            if cls.imageQueueMap[roomId].qsize() > cls.queuePoolSize:
                print("队列数据超限，系统自动去除队列数据 roomId："+roomId+"/queue size:"+str(cls.imageQueueMap[roomId].qsize()))
                cls.imageQueueMap[roomId].get_nowait()
        else:
            newQueue = queue.Queue()
            cls.imageQueueMap[roomId] = newQueue

        cls.imageQueueMap[roomId].put(img)



    @classmethod
    def getImgFromQueue(cls, roomId):
        if not cls.imageQueueMap.keys().__contains__(roomId):
            return None

        if cls.imageQueueMap[roomId].qsize() > 0:
            lastImg = cls.imageQueueMap[roomId].get_nowait()
            cls.lastImgMap[roomId] = lastImg
            return lastImg
        else:
            return cls.lastImgMap[roomId]



if __name__=="__main__":
    roomId=2
    imageQueue.putImgToQueue(roomId,"hello")
    imageQueue.putImgToQueue(roomId, "love ")
    print(imageQueue.getImgFromQueue(roomId))
    print(imageQueue.getImgFromQueue(roomId))

